<template>
    <div class="ticket ticket-wrap" >
        <div class="ticket-top">
            <z-history :type="2"></z-history>电子票
        </div>
        <div class="ticket-center">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <div class="swiper-slide" v-for="(item,index) in eleTickets" :key="index">
                        <div class="slide-top">
                            <div class="slide-num">第{{index + 1}}张</div>
                            <div class="erweima" >
                                <canvas class="canvas" :id="'canvas' + index"></canvas>
                            </div>
                            <img class="signImg" v-if="str.status==5" src="../../assets/image/已退票.png" alt="">
                            <img class="signImg" v-if="str.status==3" src="../../assets/image/已过期.png" alt="">
                            <img class="signImg" v-if="str.status==4" src="../../assets/image/退票中.png" alt="">
                            <div class="slideNo">票号：{{item.ticketNo}}</div>
                        </div>
                        <div class="slide-bottom">
                            <div class="slide-name">名称：
                                <router-link class="inline-b" :to="{name:'activityDetail',params:{id:actDetail.id}}">{{actDetail.activityTitle}}</router-link>
                            </div>
                            <div class="slide-text">时间：{{actDetail.actStartTime  |stampFormate2}}</div>
                            <div class="slide-text">
                                <p>地点 :</p>
                                <p v-if="actDetail.activityAddress && actDetail.newcity != actDetail.newprov">{{actDetail.prov}}{{actDetail.city}}{{actDetail.dist}}{{actDetail.activityAddress}}</p>
                                <p v-if="actDetail.activityAddress && actDetail.newcity == actDetail.newprov">{{actDetail.city}}{{actDetail.dist}}{{actDetail.activityAddress}}</p>
                            </div>
                            <div class="slide-text">状态：
                                <span class="font1" v-if="item.status == 1">待使用</span>
                                <span class="font1" v-if="item.status == 2">已使用</span>
                                <span class="font1" v-if="item.status == 3">已经过期</span>
                                <span class="font1" v-if="item.status == 4">退票中</span>
                                <span class="font1" v-if="item.status == 5">已退票</span>
                            </div>
                            <div class="slide-text">票价：￥{{item.ticket.price/100}}</div>
                        </div>
                    </div>
                </div>
                <div class="swiper-pagination swiper-pagination-white" style="bottom:-0.5rem;"></div>
            </div>
            <div class="hint">
                <p>使用说明</p>
                <p>1、本商品凭票兑换，一次性使用，请勿复制或者转借他人</p>
                <p>2、请截图保存至手机或者打印携带，保持二维码清晰完整</p>
                <p>3、本商品由【主办方名称】提供服务，其拥有最终解释权</p>
            </div>
        </div>
        <z-home></z-home>
    </div>
</template>

<script>
    import {actService} from '../../service/activityService'
    import 'swiper/dist/css/swiper.min.css';
    import QRCode from 'qrcode'
    export default {
        metaInfo () {
            // console.log(this);
            const title = '电子票'
            return {
                title,
                script: [{src: '/src/assets/js/swiper.min.js', type: 'text/javascript'}],
                meta: [
                    { vmid: 'description', name: 'description', content: '运联' },
                    { vmid: 'keyWords', name: 'keyWords', content: '运联' },
                ]
            }
        },
        data(){
            return{
                eleTickets: null,
                actDetail: {},
            }
        },
        mounted(){
            document.title="电子票"
            this.eleData();
        },
        methods:{
            activityDetail:function(){
                let that = this;
                actService.getActivities({activityId: that.eleTickets[0].actId}).then(function (res) {
                    that.actDetail = res.data.datas;
                    console.log(that.actDetail)
                    that.updated(); //执行轮播图
                    that.createQRCode();
                })
            },
            eleData: function(){
                const that = this;
                actService.eleTicket({randomId:that.$route.params.randomId}).then(function(res){
                    that.eleTickets = res.data.datas
                    if(that.eleTickets[0].actId){
                        that.activityDetail() //获取具体数据
                    }
                    let url = that.eleTickets[0].ticketUrl
                })
            },
            createQRCode:function () {
                const that = this;
                for(let i = 0;i<that.eleTickets.length;i++){
                    let canvasName = 'canvas'+ i;
                    let canvas = document.getElementById(canvasName+'');
                     QRCode.toCanvas(canvas,  location.origin + '/d/' + that.eleTickets[i].ticketUrl, (error) => {
                        if (error) {
                        } else {
                        }
                    })
                }
            },
            updated: function() {
                const swiper = new Swiper('.swiper-container', {
                    centeredSlides: true,
                    pagination: '.swiper-pagination',
                    paginationClickable: true,
                    loop: false,
                    speed: 600,
                    spaceBetween: 10,
                    slidesPerView: 1.15,
                    onTouchEnd: function() {
                        swiper.startAutoplay()
                    }
                });
            },
        },
    }
</script>

<style lang="less">
.ticket{
    width:100%;
    text-align: center;
    background:#6CD4F1;
    .inline-b{
        display: inline !important;
        color: #333333;
    }
    .ticket-top{
        width:100%;
        height:1.2rem;
        line-height:1.2rem;
        font-size: .48rem;
        color: #FFFFFF;
        letter-spacing: 0.3px;
        i{
            width:0.86rem;
            height:0.86rem;
            border-radius: 100%;
            background:#356A77;
            float:left;
            font-size:0.8rem;
            margin-left:0.2rem;
            margin-top:0.16rem;
            color:#fff;
            display: block;
        }
        span{
            /*margin-left:-1rem;*/
            height:1.2rem;
            line-height:1.2rem;
            font-size: 18px;
            color:#fff;
            letter-spacing: 0.3px;
        }
    }
    .canvas{
        width:100% !important;
        height:100% !important;
    }
    .ticket-center{
        width:100%;
        overflow: hidden;
        padding:0.53rem 0;
        box-sizing: border-box;
        .swiper-container{
            width:100%;
            height:15.5rem;
            overflow: visible;
            .swiper-wrapper{
                width:100%;
                height:100%;
                .swiper-slide-active{
                    width:92%;
                    height:100% !important;
                    margin-top: 0  !important;
                }
                .swiper-slide{
                    width:92%;
                    height:94%;
                    background:url("../../assets/image/ticketbk.png")no-repeat;
                    background-size:100% 100%;
                    // margin: 0 auto;
                    .slide-top{
                        width:100%;
                        height: 7.3rem;
                        padding-top:0.4rem;
                        box-sizing: border-box;
                        .slide-num{
                            width:100%;
                            height:0.8rem;
                            line-height:0.8rem;
                            font-size: .32rem;
                            color: #666666;
                            letter-spacing: 0.2px;
                        }
                        .erweima{
                            width:4.37rem;
                            height:4.3rem;
                            margin:0 auto;
                            #canvas{
                                width:100% !important;
                                height:100% !important;
                            }
                        }
                        .signImg{
                            position: absolute;
                            transform: rotate(15deg);
                            width: 2rem;
                            bottom: 3.3rem;
                            right: 3.3rem;
                            background: #fff;
                        }
                        .slideNo{
                            width:100%;
                            height:0.8rem;
                            line-height:0.8rem;
                            font-size: .3733rem;
                            color: #333333;
                            letter-spacing: 0;
                        }
                    }
                    .slide-bottom{
                        text-align: left;
                        padding:0.73rem;
                        box-sizing: border-box;
                        .slide-name{
                            width:100%;
                            height:0.8rem;
                            line-height:0.8rem;
                            overflow: hidden;
                            text-overflow:ellipsis;
                            white-space: nowrap;
                            margin:0.25rem 0;
                            font-size: .3733rem;
                            color: #333333;
                            letter-spacing: 0;
                        }
                        .slide-text{
                            width:100%;
                            margin:0.25rem 0;
                            font-size: .3733rem;
                            color: #333333;
                            letter-spacing: 0;
                            overflow: hidden;
                            p:nth-child(1){
                                width:1.2rem;
                                float:left;
                                font-size: .3733rem;
                            }
                            p:nth-child(2){
                                width:6rem;
                                float:left;
                                font-size: .3733rem;
                            }
                            span{
                                font-size: .3733rem;
                                letter-spacing: 0;
                                line-height: 20px;
                                color:#68B0F9;
                            }
                        }
                    }
                }
            }
        }
        .hint{
            width:100%;
            padding:0.6rem;
            box-sizing: border-box;
            text-align: left;
            font-size: .3733rem;
            color: #FFFFFF;
            letter-spacing: 0;
            p:nth-child(1){
                margin:0.5rem 0;
            }
        }
    }
}
</style>